//
//  ZDEmoji.m
//  ZDEmojiKeyBoard
//
//  Created by Apple on 15/11/5.
//  Copyright © 2015年 itcast. All rights reserved.
//

#import "ZDEmoji.h"
#import "ZDEmojiTool-swift.h"

@implementation ZDEmoji

- (instancetype) initWithDictionary:(NSDictionary *)dict
{
    if (self = [super init])
    {
        [self setValuesForKeysWithDictionary:dict];
    }
    
    return self;
}

//重写该方法 过滤模型中没有的属性时不会崩溃
-(void)setValue:(id)value forUndefinedKey:(NSString *)key
{
    
}


+ (instancetype) emojiWithDictionary:(NSDictionary *)dict
{
    return [[self alloc] initWithDictionary:dict];
}


+ (instancetype)emojiWithRemoveBtn:(BOOL)removeBtn
{
    ZDEmoji *emoji = [[ZDEmoji alloc] init];
    
    emoji.removeBtn = removeBtn;
    
    return emoji;
}


- (NSString *)emojiString
{
    if (self.code)
    {
//        // 扫描器
//        NSScanner *scanner = [NSScanner scannerWithString:self.code];
//        
//        // 存储扫描结果
//        // UnsafeMutablePointer<UInt32>: UInt32类型的可变指针
//        UInt32 value = 0;
//        
//        [scanner scanHexInt:&value];
//       
//        NSLog(@"扫描结果:%u", value);
//        
//        return [[NSString alloc] initWithBytes:&value length:sizeof(value) encoding:NSUTF8StringEncoding];
        
        return [ZDEmojiTool emoji:self.code];
    }
    
    return nil;
}

- (UIImage *)emojiImage
{
    if (_png)
    {
        NSString *imagePath = [NSString stringWithFormat:@"%@/Emoticons.bundle/%@/%@", [NSBundle mainBundle].bundlePath, _id, _png];
        
        return [UIImage imageWithContentsOfFile:imagePath];
    }
    
    return nil;
}


- (NSString *)description
{
//    NSArray *array = @[@"chs", @"png", @"code", @"removeBtn"];
//    
//    return [NSString stringWithFormat:@"%@", [self dictionaryWithValuesForKeys:array]];
    
    return [NSString stringWithFormat:@"表情模型：chs:%@, png:%@, code:%@, removeBtn:%d", _chs, _png, _code, _removeBtn];
}


@end
